home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_400 / 414_02 / private / _validch.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-17  |  8.7 KB  |  246 lines

  1. #define    CURSES_LIBRARY    1
  2. #include <curses.h>
  3.  
  4. #ifdef PDCDEBUG
  5. char *rcsid__validch = "$Header: C:\CURSES\private\RCS\_validch.c 2.1 1993/06/18 20:22:39 MH Rel MH $";
  6. #endif
  7.  
  8.  
  9.  
  10. /*man-start*********************************************************************
  11. *    Table for key code translation of function keys in keypad mode
  12. *    These values are for strict IBM keyboard compatibles only
  13. **man-end**********************************************************************/
  14.  
  15.  
  16. #if    defined(DOS) || defined(OS2)
  17. static chtype kptab[] =
  18. {
  19.  /* Normal Function Keys     */
  20.  0x3b, KEY_F(1), 0x3c, KEY_F(2), 0x3d, KEY_F(3), 0x3e, KEY_F(4),
  21.  0x3f, KEY_F(5), 0x40, KEY_F(6), 0x41, KEY_F(7), 0x42, KEY_F(8),
  22.  0x43, KEY_F(9), 0x44, KEY_F(10),
  23.  
  24.  /* Normal Keypad         */
  25.  0x47, KEY_HOME, 0x48, KEY_UP,   0x49, KEY_PPAGE,
  26.  0x4b, KEY_LEFT, 0x4c, KEY_B2,   0x4d, KEY_RIGHT,
  27.  0x4f, KEY_END,  0x50, KEY_DOWN, 0x51, KEY_NPAGE,
  28.  0x52, KEY_IC,   0x53, KEY_DC,
  29.  
  30.  /* Shft-Function Keys     */
  31.  0x54, KEY_F(11), 0x55, KEY_F(12), 0x56, KEY_F(13), 0x57, KEY_F(14),
  32.  0x58, KEY_F(15), 0x59, KEY_F(16), 0x5a, KEY_F(17), 0x5b, KEY_F(18),
  33.  0x5c, KEY_F(19), 0x5d, KEY_F(20),
  34.  
  35.  /* Ctl-Function Keys     */
  36.  0x5e, KEY_F(21), 0x5f, KEY_F(22), 0x60, KEY_F(23), 0x61, KEY_F(24),
  37.  0x62, KEY_F(25), 0x63, KEY_F(26), 0x64, KEY_F(27), 0x65, KEY_F(28),
  38.  0x66, KEY_F(29), 0x67, KEY_F(30),
  39.  
  40.  /* Alt-Function Keys     */
  41.  0x68, KEY_F(31), 0x69, KEY_F(32), 0x6a, KEY_F(33), 0x6b, KEY_F(34),
  42.  0x6c, KEY_F(35), 0x6d, KEY_F(36), 0x6e, KEY_F(37), 0x6f, KEY_F(38),
  43.  0x70, KEY_F(39), 0x71, KEY_F(40),
  44.  
  45.  /* Control-Keypad         */
  46.  0x77, CTL_HOME, 0x84, CTL_PGUP,
  47.  0x73, CTL_LEFT, 0x74, CTL_RIGHT,
  48.  0x75, CTL_END, 0x76, CTL_PGDN,
  49.  
  50.  /* Alt-Numbers         */
  51.  0x78, ALT_1, 0x79, ALT_2, 0x7a, ALT_3, 0x7b, ALT_4,
  52.  0x7c, ALT_5, 0x7d, ALT_6, 0x7e, ALT_7, 0x7f, ALT_8,
  53.  0x80, ALT_9, 0x81, ALT_0,
  54.  
  55.  /* Extended codes         */
  56.  0x85, KEY_F(41), 0x86, KEY_F(42), 0x87, KEY_F(43), 0x88, KEY_F(44),
  57.  0x89, KEY_F(45), 0x8a, KEY_F(46), 0x8b, KEY_F(47), 0x8c, KEY_F(48),
  58.  0x03, 0, /* NULL */
  59.  0xff, PADSLASH,     0x0d, PADENTER,      0x0a, CTL_PADENTER,
  60.  0xa6, ALT_PADENTER, 0x53, SHF_PADSTOP,   0xfc, CTL_ENTER,
  61.  0xfa, PADSTAR,      0xfd, PADMINUS,      0xfb, PADPLUS,
  62.  0x93, CTL_PADSTOP,  0x8f, CTL_PADCENTER, 0x90, CTL_PADPLUS,
  63.  0x8e, CTL_PADMINUS, 0x95, CTL_PADSLASH,  0x96, CTL_PADSTAR,
  64.  0x4e, ALT_PADPLUS,  0x4a, ALT_PADMINUS,  0xa4, ALT_PADSLASH,
  65.  0x37, ALT_PADSTAR,  0x92, CTL_INS,       0xa2, ALT_INS,
  66.  0xa3, ALT_DEL,      0x8d, CTL_UP,        0x91, CTL_DOWN,
  67.  0x94, CTL_TAB,      0xa5, ALT_TAB,       0x82, ALT_MINUS,
  68.  0x83, ALT_EQUAL,    0x99, ALT_PGUP,      0xa1, ALT_PGDN,
  69.  0x9f, ALT_END,      0x98, ALT_UP,        0xa0, ALT_DOWN,
  70.  0x9d, ALT_RIGHT,    0x9b, ALT_LEFT,      0x1c, ALT_ENTER,
  71.  0x97, ALT_HOME,     0x01, ALT_ESC,       0x0e, ALT_BKSP,
  72.  0x29, ALT_BQUOTE,   0x1a, ALT_LBRACKET,  0x1b, ALT_RBRACKET,
  73.  0x27, ALT_SEMICOLON,0x28, ALT_FQUOTE,    0x33, ALT_COMMA,
  74.  0x34, ALT_STOP,     0x35, ALT_FSLASH,    0x2b, ALT_BSLASH,
  75.  
  76.  /* Alt-Alphabet         */
  77.  0x1e, ALT_A, 0x30, ALT_B, 0x2e, ALT_C, 0x20, ALT_D,
  78.  0x12, ALT_E, 0x21, ALT_F, 0x22, ALT_G, 0x23, ALT_H,
  79.  0x17, ALT_I, 0x24, ALT_J, 0x25, ALT_K, 0x26, ALT_L,
  80.  0x32, ALT_M, 0x31, ALT_N, 0x18, ALT_O, 0x19, ALT_P,
  81.  0x10, ALT_Q, 0x13, ALT_R, 0x1f, ALT_S, 0x14, ALT_T,
  82.  0x16, ALT_U, 0x2f, ALT_V, 0x11, ALT_W, 0x2d, ALT_X,
  83.  0x15, ALT_Y, 0x2c, ALT_Z,
  84.  0x0f, KEY_BACKTAB,
  85.  0x100, -1
  86. };
  87.  /* End of kptab[]         */
  88. #endif
  89.  
  90.  
  91.  
  92.  
  93. #ifdef    FLEXOS
  94. chtype    kptab[] =
  95. {
  96.  /* Normal Function Keys     */
  97.  0x1001, KEY_F(1), 0x1002, KEY_F(2), 0x1003, KEY_F(3), 0x1004, KEY_F(4),
  98.  0x1005, KEY_F(5), 0x1006, KEY_F(6), 0x1007, KEY_F(7), 0x1008, KEY_F(8),
  99.  0x1009, KEY_F(9), 0x100A, KEY_F(10),
  100.  
  101.  /* Normal Keypad         */
  102.  0x2018, KEY_HOME, 0x2010, KEY_UP, 0x2014, KEY_PPAGE,
  103.  0x2012, KEY_LEFT, 0x2035, KEY_B2, 0x2013, KEY_RIGHT,
  104.  0x2008, KEY_LL, 0x2011, KEY_DOWN, 0x2015, KEY_NPAGE,
  105.  0x2009, KEY_IC, 0x200A, KEY_DC,
  106.  
  107.  /* Shft-Function Keys     */
  108.  0x1401, KEY_F(11), 0x1402, KEY_F(12), 0x1403, KEY_F(13), 0x1404, KEY_F(14),
  109.  0x1405, KEY_F(15), 0x1406, KEY_F(16), 0x1407, KEY_F(17), 0x1408, KEY_F(18),
  110.  0x1409, KEY_F(19), 0x140A, KEY_F(20),
  111.  
  112.  /* Ctl-Function Keys     */
  113.  0x1101, KEY_F(21), 0x1102, KEY_F(22), 0x1103, KEY_F(23), 0x1104, KEY_F(24),
  114.  0x1105, KEY_F(25), 0x1106, KEY_F(26), 0x1107, KEY_F(27), 0x1108, KEY_F(28),
  115.  0x1109, KEY_F(29), 0x110A, KEY_F(30),
  116.  
  117.  /* Alt-Function Keys     */
  118.  0x1201, KEY_F(31), 0x1202, KEY_F(32), 0x1203, KEY_F(33), 0x1204, KEY_F(34),
  119.  0x1205, KEY_F(35), 0x1206, KEY_F(36), 0x1207, KEY_F(37), 0x1208, KEY_F(38),
  120.  0x1209, KEY_F(39), 0x120A, KEY_F(40),
  121.  
  122.  /* Control-Keypad         */
  123.  0x2118, CTL_HOME, 0x2114, CTL_PGUP,
  124.  0x2112, CTL_LEFT, 0x2113, CTL_RIGHT,
  125.  0x2108, CTL_END, 0x2115, CTL_PGDN,
  126.  
  127.  /* Alt-Numbers         */
  128.  0x2231, ALT_1, 0x2232, ALT_2, 0x2233, ALT_3, 0x2234, ALT_4,
  129.  0x2235, ALT_5, 0x2236, ALT_6, 0x2237, ALT_7, 0x2238, ALT_8,
  130.  0x2239, ALT_9, 0x2230, ALT_0,
  131.  
  132.  /* Alt-Alphabet         */
  133.  0x0200 | (unsigned) 'A', ALT_A, 0x0200 | (unsigned) 'B', ALT_B,
  134.  0x0200 | (unsigned) 'C', ALT_C, 0x0200 | (unsigned) 'D', ALT_D,
  135.  0x0200 | (unsigned) 'E', ALT_E, 0x0200 | (unsigned) 'F', ALT_F,
  136.  0x0200 | (unsigned) 'G', ALT_G, 0x0200 | (unsigned) 'H', ALT_H,
  137.  0x0200 | (unsigned) 'I', ALT_I, 0x0200 | (unsigned) 'J', ALT_J,
  138.  0x0200 | (unsigned) 'K', ALT_K, 0x0200 | (unsigned) 'L', ALT_L,
  139.  0x0200 | (unsigned) 'M', ALT_M, 0x0200 | (unsigned) 'N', ALT_N,
  140.  0x0200 | (unsigned) 'O', ALT_O, 0x0200 | (unsigned) 'P', ALT_P,
  141.  0x0200 | (unsigned) 'Q', ALT_Q, 0x0200 | (unsigned) 'R', ALT_R,
  142.  0x0200 | (unsigned) 'S', ALT_S, 0x0200 | (unsigned) 'T', ALT_T,
  143.  0x0200 | (unsigned) 'U', ALT_U, 0x0200 | (unsigned) 'V', ALT_V,
  144.  0x0200 | (unsigned) 'W', ALT_W, 0x0200 | (unsigned) 'X', ALT_X,
  145.  0x0200 | (unsigned) 'Y', ALT_Y, 0x0200 | (unsigned) 'Z', ALT_Z,
  146.  
  147.  0x0200 | (unsigned) 'a', ALT_A, 0x0200 | (unsigned) 'b', ALT_B,
  148.  0x0200 | (unsigned) 'c', ALT_C, 0x0200 | (unsigned) 'd', ALT_D,
  149.  0x0200 | (unsigned) 'e', ALT_E, 0x0200 | (unsigned) 'f', ALT_F,
  150.  0x0200 | (unsigned) 'g', ALT_G, 0x0200 | (unsigned) 'h', ALT_H,
  151.  0x0200 | (unsigned) 'i', ALT_I, 0x0200 | (unsigned) 'j', ALT_J,
  152.  0x0200 | (unsigned) 'k', ALT_K, 0x0200 | (unsigned) 'l', ALT_L,
  153.  0x0200 | (unsigned) 'm', ALT_M, 0x0200 | (unsigned) 'n', ALT_N,
  154.  0x0200 | (unsigned) 'o', ALT_O, 0x0200 | (unsigned) 'p', ALT_P,
  155.  0x0200 | (unsigned) 'q', ALT_Q, 0x0200 | (unsigned) 'r', ALT_R,
  156.  0x0200 | (unsigned) 's', ALT_S, 0x0200 | (unsigned) 't', ALT_T,
  157.  0x0200 | (unsigned) 'u', ALT_U, 0x0200 | (unsigned) 'v', ALT_V,
  158.  0x0200 | (unsigned) 'w', ALT_W, 0x0200 | (unsigned) 'x', ALT_X,
  159.  0x0200 | (unsigned) 'y', ALT_Y, 0x0200 | (unsigned) 'z', ALT_Z,
  160.  
  161.  0x0f, KEY_BACKTAB,
  162.  
  163.  /* End of kptab[]         */
  164.  0x100, -1
  165. };
  166. #endif
  167.  
  168.  
  169.  
  170.  
  171. /*----------------------------------------------------------------------
  172. $ PDC_validchar()    - validate/translate passed character
  173. $
  174. $ PDCurses Description:
  175. $    This is a private PDCurses function.
  176. $
  177. $    Checks that 'c' is a valid character, and if so returns it,
  178. $    with function key translation applied if 'w' has keypad mode
  179. $    set.  If char is invalid, returns -1.
  180. $
  181. $ PDCurses Return Value:
  182. $    This function returns -1 if the passed character is invalid, or
  183. $    the WINDOW* 'w' is NULL, or 'w's keypad is not active.
  184. $
  185. $    This function returns 0 under Flexos if the passed character
  186. $    is 0x0300.  (-:Forget why.  --Frotz    911130:-)
  187. $
  188. $    Otherwise, this function returns the PDCurses equivalent of the
  189. $    passed character.  See the function key and key macros in
  190. $    <curses.h>
  191. $
  192. $ PDCurses Errors:
  193. $    There are no errors defined for this routine.
  194. $
  195. $ Portability:
  196. $    PDCurses    chtype    PDC_validchar( chtype c );
  197. $
  198. $----------------------------------------------------------------------
  199. */
  200. chtype    PDC_validchar(chtype c)
  201. {
  202. extern    WINDOW*    _getch_win_;
  203. /* extern    WINDOW*    w;*/   /* w defined in wgetch() as static - _getch_win_ */
  204.                         /* is the same window - all references to w changed*/
  205.                         /* to _getch_win_ - marked with @@ */
  206.  
  207.     chtype    *scanp;
  208.  
  209. #ifdef PDCDEBUG
  210.     if (trace_on) PDC_debug("PDC_validchar() - called\n");
  211. #endif
  212.  
  213.     if (_getch_win_ == (WINDOW *)NULL)
  214.         return (-1);    /* bad window pointer      */
  215.  
  216. #ifdef    FLEXOS
  217.     if (c == 0x0300)
  218.         return (0);    /* special case, ^@ = NULL      */
  219. #endif
  220.     if (!(c & ~A_CHARTEXT))    return (c);  /* normal character */
  221.     if (!(_getch_win_->_use_keypad))    return (-1); /* skip if keys if !keypad mode */
  222.  
  223. #if    defined (DOS) || defined (OS2)
  224.     /*
  225.     * Under DOS, extended keys are in the upper byte.  Shift down for a
  226.     * comparison.
  227.     */
  228.     c = (c >> 8) & A_CHARTEXT;
  229. #endif
  230.  
  231. #ifdef UNIX
  232. /* INCOMPLETE */
  233. #else
  234.     scanp = kptab;
  235.     while (*scanp > 0)    /* search for value         */
  236.     {            /* (stops on table entry 0x100) */
  237.         if (*scanp++ == c)
  238.         {
  239.             return (*scanp);    /* found, return it */
  240.         }
  241.         scanp++;
  242.     }
  243.     return( -1 );        /* not found, invalid */
  244. #endif
  245. }
  246.